import time
from agent import Agent
from world import *

    # World Setup
class SimParams():
    # instance used to hold simulation level parameters
    # params:
    #   world_size:     world is a grid, world_size^2
    #   num_agents:     number of agents in the sim
    #   resources:      raw items that are refined to make artifcats
    #   round length:   num turns in a single round
    def __init__(self, world_size, num_agents, resources, rounds_per_run,
            num_rounds_to_completion):
        self.world_size = world_size
        self.num_agents = num_agents
        self.resources = resources
        self.rounds_per_run = rounds_per_run
        self.num_rounds_to_completion = num_rounds_to_completion
    
    #Resources w/ Frequencies distributions 

    # temp notes:
    # this list to be set up by modeller; 
    # resources, below, are what's used in sim
    # resource frequencies will be variableized
    # resource density will be determined by:
    # set total avail, then randomly assign subsets of the resource
    # eg total = 0.4, a = rand(0, 0.4), total_rem = total - 0 - a.freg
    # repeat for all reso's, could say that if early ones take up entire range, 
    # other ones get some super small value (0.01 or sth)
    
def run_round(num_agents, world_size):

    resources = generate_resources()

    # Main line(s) to set up sim-wide params
    # TODO - move num_rounds_to_completion to somwhere else...
    sim_params = SimParams(\
            world_size=world_size,\
            num_agents=num_agents,\
            resources=resources,\
            rounds_per_run=800,\
            num_rounds_to_completion="inc")
    

    # Build world, using world.py keep track of resource counts
    world = World(sim_params)
    
    # Setup Agents
    setup_agents(sim_params, world)

    # End World Setup
    ################################################################################

    # Round Logic
    for round_num in range(sim_params.rounds_per_run):
        if sim_params.num_rounds_to_completion == "inc":
            for agent in world.agent_list:
                agent.act(world, round_num, sim_params)
                ("^^^^^^^^^^")
            # demo mode - comment out this line if running for data
            draw_world(sim_params, world, round_num)
        else:
            pass

    return sim_params.num_rounds_to_completion,\
            world.initial_raw_resource_count,\
            world.harvested_resource_count
